Compiling C code to dll

Look at the sample.c and sample.h files for C code and header, respectively.

Install mingw-w64 from: http://sourceforge.net/projects/mingw-w64/

put mingw64\bin\ folder into path and compile it with:


In [1]:
!!gcc -c sample.c


Out[1]:
[]

In [2]:
!!gcc -shared -o sample.dll sample.o -Wl,--out-implib,libsample.a


Out[2]:
[]

Wrapping into py 3.4


In [3]:
import ctypes

In [4]:
ctypes.util.find_library('sample.o')


Out[4]:
'sample.o'

Load the dll:


In [5]:
_mod = ctypes.cdll.LoadLibrary('sample')

Define a wrapper to the dll function


In [6]:
in_mandel = _mod.in_mandel
in_mandel.argtypes = (ctypes.c_double, ctypes.c_double, ctypes.c_int)
in_mandel.restype = ctypes.c_int

Use it:


In [7]:
in_mandel(1., 4., 1)


Out[7]:
5

For more functions look at the sample.py.